package com.jdk7;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import org.junit.Test;

public class NewFeature {
	@Test
	public static void testNumber(){
		// 数字可带下划线
		int one_million = 1_000_000;
		// 二进制数字
		int binary = 0b1001_1001;

		System.out.println(one_million);
		System.out.println(binary);
		System.out.println(1_000_000);
	}

	public static void testTryResource() {
		
		// try resource 自动释放资源，不需要finally了。
		// 资源必须实现 Closeable 接口
		try (BufferedReader in = new BufferedReader(new FileReader("in.txt"));
				BufferedWriter out = new BufferedWriter(new FileWriter("out.txt"))) {
			int charRead;
			while ((charRead = in.read()) != -1) {
				System.out.printf("%c ", (char) charRead);
				out.write(charRead);
			}
		} catch (IOException | NullPointerException ee) {// 合并异常写法
			ee.printStackTrace();
		}
	}
}
